package com.ziven.common.widget.value;

import android.view.View;
import android.widget.Checkable;

import androidx.annotation.NonNull;

import com.ziven.easygo.util.ViewHelper;

/**
 * @author Ziven
 */
public final class Checked extends Value {

    public static Checked unChecked() {
        return checked(false);
    }

    public static Checked checked() {
        return checked(true);
    }

    public static Checked checked(boolean checked) {
        return new Checked().accept(my -> my.value = checked);
    }

    private Checked() {}

    @Override
    protected void takeEffect(@NonNull ViewHelper<? extends View> helper) {
        View view = helper.getView();
        if(view instanceof Checkable) {
            value(Boolean.class, value -> ((Checkable) view).setChecked(value));
        }
    }
}
